Google News
logo
jQuery - Interview Questions
What is the difference between bind() vs live() vs delegate() methods in jQuery?
bind() : this method registers the event handler directly to the required DOM element.
$(“#members a”).bind(“click”, function(f){….});
This means any matching anchors will have this event handler attached!
 
live() : this method attaches the event handler to the root of the document. This means one handler can be used for all events that propagated to the root. The handler is thus attached only once.
 
delegate() : in this method, you can choose where to attach the handler. This is the most efficient and robust method for delegation.
 
Eg:
$(“#members”).delegate(“ul li a”, “click”, function(f){….});
Advertisement